package org.infodavid.common.ejb.components;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import org.infodavid.common.impl.model.EMailImpl;

/**
 * The Class EMailComponent.
 */
@Embeddable
public class EMailComponent extends EMailImpl {

	/** serialVersionUID. */
	private static final long serialVersionUID = -7948981883198179487L;

	/**
	 * The Constructor.
	 * @throws Exception the exception
	 */
	protected EMailComponent() throws Exception {
		super();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.impl.EMailImpl#getType()
	 */
	@Override
	@Enumerated(EnumType.STRING)
	@Column(name = TYPE, nullable = true, length = 16)
	public EMailType getType() {
		return super.getType();
	}

	/*
	 * (non-Javadoc)
	 * @see org.infodavid.common.model.entities.impl.EMailImpl#getValue()
	 */
	@Override
	@Column(name = "value", nullable = false, length = 64)
	public String getValue() {
		return super.getValue();
	}

	/**
	 * Post store.
	 */
	@PostLoad
	@PostUpdate
	@PostPersist
	protected void postStore() {
		if (getType() == null) {
			setType(EMailType.UNDEFINED);
		}
	}

	/**
	 * Pre store.
	 */
	@PreUpdate
	@PrePersist
	protected void preStore() {
		if (getType() == null) {
			setType(EMailType.UNDEFINED);
		}
	}
}
